package testLayer;

import static org.junit.Assert.*;
import modelLayer.Person;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * This class is a JUnit test case of the Person class.
 * 
 * @author A. Kelemen
 * 
 * @Version 1.1
 * 			
 */
public class PersonTest {
	
	private Person person;
	
	/**
	 * Initializes a test object.
	 * 
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		
		person = new Person("John Johnsen", "Bakkevej 1", "Byen", "Landet", "12345678", "johnsen@johnsen.com", 1234);

	}

	@After
	public void tearDown() throws Exception {
		
		
		
	}

	/**
	 * Tests the constructor with parameters taking the parameters of the test object.
	 */
	@Test
	public void testPersonWithParameters() {
		
		assertTrue(this.person != null);
		
	}

	/**
	 * Tests the empty constructor without parameters. Initializes a new person object.
	 */
	@Test
	public void testPerson() {
		
		this.person = new Person();
		assertTrue(this.person != null);
		
	}
	
	/**
	 * Tests the constructor with an incorrect String value. 
	 * This test method expects an exception and asserts true if an exception has been thrown.
	 */
	@Test (expected = IllegalArgumentException.class)
	public void testPersonthrowsException() {
		
		this.person = new Person("","Bakkevej 1", "Byen", "Landet", "12345678", "johnsen@johnsen.com", 1234);
		
	}
	
	/**
	 * Tests the constructor with incorrect String value.
	 * The test method catches the exception and prints it on the console.
	 */
	@Test 
	public void testPersonthrowsExceptionName() {
		
		try {
			this.person = new Person("","Bakkevej 1", "Byen", "Landet", "12345678", "johnsen@johnsen.com", 1234);
		}
		catch (IllegalArgumentException e) {
			System.out.println(e.getMessage());
		}
		
	}
	
	/**
	 * Test the constructor with an incorrect integer value.
	 * The test method catches the exception and prints it on the console.
	 */
	@Test 
	public void testPersonthrowsExceptionZipCode() {
		
		try {
			this.person = new Person("John Johnsen", "Bakkevej 1", "Byen", "Landet", "12345678", "johnsen@johnsen.com", 10000);
		}
		catch (IllegalArgumentException e){
			System.out.println(e.getMessage());
		}

	}
	
	/**
	 * Tests if the value of the getName() method equals the expected name value of the test object.
	 */
	@Test
	public void testGetName() {
		
		assertEquals("John Johnsen", this.person.getName());
		
	}
	
	/**
	 * Tests if the value of the getAddress() method equals the expected address value of the test object.
	 */
	@Test
	public void testGetAddress() {
		
		assertEquals("Bakkevej 1", this.person.getAddress());
		
	}
	
	/**
	 * Tests if the value of the getCity() method equals the expected city value of the test object.
	 */
	@Test
	public void testGetCity() {
		
		assertEquals("Byen", this.person.getCity());
		
	}
	
	/**
	 * Tests if the value of the getCountry() method equals the expected country value of the test object.
	 */
	@Test
	public void testGetCountry() {
		
		assertEquals("Landet", this.person.getCountry());
		
	}
	
	/**
	 * Tests if the value of the getPhoneNo() method equals the expected phoneNo value of the test object.
	 */
	@Test
	public void testGetPhoneNo() {
		
		assertEquals("12345678", this.person.getPhoneNo());
		
	}
	
	/**
	 * Tests if the value of the getEmail() method equals the expected email value of the test object.
	 */
	@Test
	public void testGetEmail() {
		
		assertEquals("johnsen@johnsen.com", this.person.getEmail());
		
	}
	
	/**
	 * Tests if the value of the getZipCode() method equals the expected zipCode value of the test object.
	 */
	@Test
	public void testGetZipCode() {
		
		assertEquals(1234, this.person.getZipCode());
		
	}

}
